import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

// require.context('指定需要导入文件的路径',是否递归获取,正则匹配需要加载的文件类型)
const req = require.context('./modules', false, /\.js$/)
// console.log(req.keys())
const nName = req.keys().map(item => item.split('./')[1]).map(item => item.split('.js')[0])
// console.log(nName)
const mModel = req.keys().map(req)
// console.log(mModel)

const obj = {}
nName.forEach((item, index) => {
  obj[item] = mModel[index].default
})
// console.log(obj)

// 总仓库
const store = new Vuex.Store({
  modules: obj,
  getters
})

export default store
